import asyncio

from app.core import logger_manager
from app.crud.dept_crud import get_dept_by_id
from app.crud.user_crud import (
    get_menu_by_userid,
    get_role_by_userid,
    get_user_by_username,
)
from app.database.db import async_db_session

logger = logger_manager.get_logger(__name__)


async def test_create_user():
    async with async_db_session() as session:
        user = await get_user_by_username(session=session, username="root")
        logger.info(user.model_dump_json(indent=2))

        roles = await get_role_by_userid(session=session, user_id=user.id)
        for role in roles:
            logger.info(role.model_dump_json(indent=2))

        menus = await get_menu_by_userid(session=session, user_id=user.id)
        for menu in menus:
            logger.info(menu.model_dump_json(indent=2))

        dept = await get_dept_by_id(session=session, dept_id=user.dept_id)
        if dept:
            logger.info(dept.model_dump_json(indent=2))


if __name__ == "__main__":
    asyncio.run(test_create_user())
